// 添加考核 api
let express = require('express')
let router = express()
let mongoose = require('mongoose')
let ShowDetail = mongoose.model('ShowDetail')
router.post('/', (req, res) => {
  if (req.body.type === 'query') {
    ShowDetail.find({date: req.body.date}, (err, result) => {
      if (err) {
        res.send({
          code: 0,
          message: err
        })
      } else {
        if (result.length) {
          result = result[0]
        } else {
          result = null
        }
        res.send({
          code: 1,
          resObject: result
        })
      }
    })
  } else {
    // 删除重复数据
    ShowDetail.remove({date: req.body.date}, (err, data) => {
      if (err) {
        res.send({
          code: 0,
          message: err
        })
      }
    })
    let showDetail = new ShowDetail({
      date:req.body.date,
      flag:req.body.flag
    })
    showDetail.save((err) => {
      if (err) {
        res.send({
          code: 0,
          message: err
        })
      } else {
        console.log('考核详情是否查看:' + req.body.flag + ' ' + req.body.date)
        res.send({
          code: 1,
          resObject: '修改成功'
        })
      }
    })
  }
  
})

module.exports = router
